package com.xzcedu.regexp.homework;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 徐州城
 * @version 1.0
 */
@SuppressWarnings("all")
public class Homework03 {
    public static void main(String[] args) {

        //String content = "http://www.sohu.com:8080/abc/xxx/yyy/////inde@#$%x.htm";

        //因为正则表达式是根据要求来编写的，所以，如果有需求的话，可以适当的改善
        String content = "http://www.sohu.com:8080/abc/xxx/yyy////inde@#$%.htm";
        String regStr = "^([a-zA-z]+)://([a-zA-Z.]+):(\\d+)[\\w-/]*/([\\w.@#$%]+)$";
        Pattern pattern = Pattern.compile(regStr);
        Matcher matcher = pattern.matcher(content);

        if (matcher.matches()) {//整体匹配
            System.out.println("整体匹配=" + matcher.group(0));
            System.out.println("协议: " + matcher.group(1));
            System.out.println("域名: " + matcher.group(2));
            System.out.println("端口: " + matcher.group(3));
            System.out.println("文件名: " + matcher.group(4));
        } else {
            System.out.println("不符合要求");
        }
    }
}
